package com.goods.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.goods.pojo.Book;
import com.goods.pojo.Category;
import com.goods.pojo.Order;
import com.goods.pojo.OrderItem;
import com.goods.pojo.Page;
import com.goods.pojo.User;

public interface OrderMapper {

	// 根据订单信息（动态SQL）查询所有订单
	List<Order> find(@Param("uid")String uid,@Param("status")int status,@Param("pc")int pc,@Param("ps")int ps);


	// 查询订单总记录数（动态SQL）
	int Count(@Param("uid")String uid,@Param("status")int status); 

	// 查询一本书详细信息
	@Select("select * from t_book where bid = #{0}")
	Book findByBid(String bid);
	
	// 查询指定的order下它的所有OrderItem
	@Select("select * from t_orderitem where oid=#{0}")
	List<OrderItem> loadOrderItem(String oid);
	
	// 查询订单所有者
	@Select("select * from t_user where uid = #{0}")
	User findUserByUid(String uid);

	// 查询订单状态
	@Select("select status from t_order where oid = #{0}")
	int findStatus(String oid);
	
	// 修改订单状态
	@Update("update t_order set status = #{1} where oid = #{0}")
	int updateStatus(String oid, int status);
	
	// 加载订单
	@Select("select * from t_order where oid = #{0}")
	Order load(String oid);

	// 生成大订单
	@Insert("insert into t_order values(#{oid},#{ordertime},#{total},#{status},#{address},#{uid})")
	int add(Order order);
	
	//  生成小订单
	@Insert("insert into t_orderitem values(#{orderItemId},#{quantity},#{subtotal},#{bid},#{bname},#{currPrice},#{image_b},#{oid})")
	int addOrderItem(OrderItem orderItem);
}
